$(function () {

    $("body").css("opacity","1")

    $("#tijiao").click(function () {
        console.log(1);
        $(this).css({"background-color": "#007dd2", "color": "white"})
        $("#jgchaxun").css({"background-color": "white", "color": "black"})
        $("#tijiao1").show(500)
        $("#jgchaxun1").hide(500)
    });

    $("#jgchaxun").click(function () {
        console.log(1);
        $(this).css({"background-color": "#007dd2", "color": "white"})
        $("#tijiao").css({"background-color": "white", "color": "black"})
        $("#jgchaxun1").show(500)
        $("#tijiao1").hide(500)
    });


    var username = localStorage.getItem("username");
    $.post("/xjxt/jsbiyechaxun?username=" + username + "", function (res) {

        var hehe = JSON.parse(res);
        console.log(hehe);
        $("#jschaxun").append("<tr>" + "<td>" + "姓名" + "</td>" + "<td>" + "说明" + "</td>" + "<td>" + "下载" + "</td>" + "<td>" + "状态" + "</td>" + "</tr>");
        $.each(hehe, function (colIndex, col) {
        	if (col.jieguo == "0")
            {col.jieguo = "尚未处理"}
        	else{col.jieguo = "已经处理"}
            var th;
            th += "<td>" + "<a href='#' id='" + col.username + "'>" + col.name + "</a>" + "</td>" + "<td>" + col.shuoming + "</td>" + "<td>" + "<a href=http://localhost:8080/xjxt/sheji/" + col.dizhi + " download=" + col.dizhi + ">" + col.dizhi + "</a>" + "</td>" + "<td>" + col.jieguo + "</td>";
            $("#jschaxun").append("<tr>" + th + "</tr>");

            $("#" + col.username + "").click(function () {
                $.post("/xjxt/jsbiyeshenghe", {
                    "username": col.username,
                    "laoshi": col.laoshi
                }, function (res) {

                    var hehe = JSON.parse(res);
                    console.log(hehe);

                    $("#name").val(hehe[0].name);
                    $("#shuoming").val(hehe[0].shuoming);
                    $("#xiazai").html(hehe[0].dizhi);
                    $("#xiazai").attr("href", "http://localhost:8080/xjxt/sheji/" + hehe[0].dizhi + "");
                    $("#xiazai").attr("download", hehe[0].dizhi);
                    $("#jianyi").attr("value", hehe[0].jianyi);
                    $("#shenghe").val(hehe[0].jieguo);


                    $("#jgchaxun").css({"background-color": "#007dd2", "color": "white"})
                    $("#tijiao").css({"background-color": "white", "color": "black"})
                    $("#jgchaxun1").show(500)
                    $("#tijiao1").hide(500)


                    $("#cjtijiao").click(function () {

                        $.post("/xjxt/jsbiyeshenghet", {
                            "username": hehe[0].username,
                            "jieguo": $("#shenghe").val(),
                            "jianyi": $("#jianyi").val(),
                        }, function (res) {
                            if(res == "1")
                            {
                                alert("修改成功");
                            }

                            if(res == "2")
                            {
                                alert("修改失败");
                            }
                            window.location.reload()
                        });

                    });
                });
            });
        });


    });
});

